import json

from django.db import models

class MainMenu(models.Model):
    main_menu_id = models.IntegerField(verbose_name='菜单ID')
    main_menu_name = models.CharField(max_length=255, verbose_name='菜单名称', null=False)
    main_menu_url = models.CharField(max_length=255, null=True, blank=True, verbose_name='菜单地址')

    # 手动序列化
    def to_dict(self):
        return {
            'main_menu_id': self.main_menu_id,
            'main_menu_name': self.main_menu_name,
        }

    class Meta:
        db_table = 'main_menu'

class SubMenu(models.Model):
    main_menu_id = models.IntegerField( null=True, blank=True, verbose_name='一级菜单ID')
    submenu_id = models.IntegerField( null=True, blank=True, verbose_name='二级菜单ID')
    submenu_name = models.CharField(max_length=255, verbose_name='二级菜单名称', null=False)
    submenu_type = models.CharField(max_length=255, null=True, blank=True, verbose_name='二级菜单类型')
    submenu_url = models.CharField(max_length=255, null=True, blank=True, verbose_name='二级菜单地址')

    def to_dict(self):
        return{
            'main_menu_id': self.main_menu_id,
            'submenu_id': self.submenu_id,
            'submenu_name': self.submenu_name,
            'submenu_type': self.submenu_type,
            'submenu_url': self.submenu_url,
        }

    class Meta:
        db_table = 'sub_menu'